#ifndef XELIX_PROTO_H
#define XELIX_PROTO_H

#include <stdint.h>

#define ERR (-1)
#define XELIX_PROTO_HEADER (uint16_t)0xAA55
#define XELIX_PROTO_STATIC 10+1

typedef enum{
    e_xelix_msg_error            = 0,
    e_xelix_msg_data_push        = 1,
    e_xelix_msg_data_response    = 2,
    e_xelix_msg_logic_push       = 3,
    e_xelix_msg_logic_response   = 4,
    e_xelix_msg_control_push     = 5,
    e_xelix_msg_control_response = 6,
    e_xelix_msg_last
}e_xelix_msg_t, *p_xelix_msg_t;


//	|	HEADER 2B	|	MSG Type 2B	|	MSG seq nr 2B	|	MSG content sz 2B	|	MSG content xB	|	CRC16	|
//	|	0xAA 0x55	|	0x00 0x01	|	0x1A 0xDB		|	0x00 0x01			| 	0x05			| 0xE6 0x54 |
typedef struct _s_xelix_proto_t{
    uint16_t        msg_header;
    uint16_t   		msg_type;
    uint16_t		msg_seq_num;
    uint16_t        msg_sz;
    void            *msg_content;
    uint16_t        crc16;
}s_xelix_proto_t, *p_xelix_proto_t;

typedef enum {
    e_xelix_fsm_error       = 0,    /* initial state */
    e_xelix_fsm_header      = 1,    /* message header --2B-- */
    e_xelix_fsm_pmsg_type   = 2,    /* xelix protocol message type --2B-- */
    e_xelix_fsm_pmsg_seq_num= 3,	/* xelix protocol message sequence number --2B-- */
    e_xelix_fsm_cont_sz     = 4,    /* xelix communication message size --2B-- */
    e_xelix_fsm_content     = 5,    /* xelix communication message content message size --xB-- */
    e_xelix_fsm_crc16       = 6,    /* xelix protocol message crc16 checksum --2B-- */
    e_xelix_fsm_last                /* last state, must be less than this */
}e_xelix_proto_fsm;

/* Global function headers */
int xelix_msg_create(p_xelix_proto_t data, void *buff, int *sz);
int xelix_msg_parse(void *buff, p_xelix_proto_t data, int *sz);

#endif /* XELIX_PROTO_H */
/* End of file */
